home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / text1 / macintosh / texix.turbomac < prev   
Text File  |  1991-10-23  |  14KB  |  592 lines

  1. % Version 1.0; Dean Guenther; 4/1/86
  2. % Version 1.1; Dean Guenther; 12/87
  3. % Version 1.2; Dean Guenther; 6/28/88
  4. These are the changes necessary to use TEXIX with Turbo mac pascal.
  5.  
  6. @x   line 6
  7.     \centerline{{\twelvept For IBM VM/CMS Pascal/VS}}
  8. @y
  9.     \centerline{{\twelvept For Macintosh Turbo Pascal}}
  10. @z
  11.  
  12. @x   line 68
  13. \def\PASCAL{{\sc PASCAL/VS}}
  14. @y
  15. \def\PASCAL{{\sc Macintosh Turbo Pascal}}
  16. @z
  17.  
  18. @x   line 87
  19. @ The @^TEXIX@>
  20. program is written entirely in WEB, except for an external
  21. procedure, {\it plsort}, which is written in @^PL/1@> PL/1.
  22. This was necessary since
  23. \PASCAL\  cannot call
  24. @:plsort@>
  25. Syncsort @^SYNCSORT@>
  26. to do an internal sort, and PL/1 can.
  27. @y
  28. @ The @^TEXIX@>
  29. program is written entirely in WEB, except for an internal
  30. sort which uses the TURBO Pascal DataBase Toolbox sort.
  31. This was necessary since
  32. \PASCAL\  cannot itself do a sort.
  33. @z
  34.  
  35. @x   line 107
  36. segment texix;
  37. procedure texix(ix:char); external;
  38. procedure texix;
  39. @y
  40. program texix;
  41. @{$U Sort@}
  42. uses sane, MemTypes, QuickDraw, OSIntf, Sort, toolintf; @/
  43. @{It is required to convert all @@ into a shift-6 \^ {} before
  44. compiling this with turbo pascal@}  @{ There is one exception,
  45. the line at the bottom that calls the Sort routine should retain
  46. the at signs.@}
  47.  
  48. @z
  49.  
  50. @x   line 119
  51. @<Global Var...@>=
  52. sysprint:text;
  53. @!ix_file :text;
  54. @y
  55. @<Global Var...@>=
  56. sysprint:text;
  57. @!ix_file :text;
  58. @!curslist:CursorList;
  59. @!total_recs:integer;
  60. @!clock_time:integer;
  61. @z
  62.  
  63. @x   line 123
  64. @ The {\it sort\_file} is used for the internal sort only. The \text1\  user
  65. never has access to it.
  66.  
  67. @<Global Var...@>=
  68. @!sort_file :file of sort_type;
  69. @y
  70. @ The {\it sort\_file} used with Pascal/VS is not needed in \PASCAL.
  71. @z
  72.  
  73. @x   line 136
  74. @d dosubstr == substr
  75. @d doindex == index
  76. @y
  77. @d dosubstr == copy
  78. @d doindex == getindex
  79. @z
  80.  
  81. @x   line 142
  82. @d getout == return
  83. @d messages == sysprint
  84. @y
  85. @d getout == exit
  86. @d messages == output
  87. @z
  88.  
  89. @x   line 147
  90. @d max_field = 300
  91. @d max_levels = 3
  92. @d max_lrecl = 2048
  93. @y
  94. @d max_field = 255
  95. @d max_levels = 3
  96. @d max_lrecl = 255
  97. @z
  98.  
  99. @x   line 147
  100. in_record := dosubstr(in_record,1 + #)
  101. @y
  102. in_record := dosubstr(in_record,1 + #,length(in_record))
  103. @z
  104.  
  105. @x   line 160
  106. @d string_type(#) == string(#)
  107. @y
  108. @d string_type(#) == string[#]
  109. @z
  110.  
  111. @x   line 206
  112. @ This is arbitrary, but
  113. there should never be more than 8 indicies.
  114.  
  115. @d s_file_number == '9'
  116. @y
  117. @ The variable {\it s\_file\_number} is not used in  \PASCAL\ and
  118. is omitted here.
  119. @z
  120.  
  121. @x   line 253
  122.   ccat := x ccat_temp y;
  123. @y
  124.   ccat := concat(x,y);
  125. @z
  126.  
  127. @x   line 277
  128. @p procedure reset_file(file_number:char);
  129. begin
  130. if file_number = '9' then reset(sort_file,
  131. 'NAME=TEXT1$$.OUTSORT.A,LRECL=1857,RECFM=V')
  132. else reset(ix_file,
  133. ccat(ccat('NAME=TEXT1$$.IX',str(file_number)),'.A'));
  134. end;
  135. @y
  136. @p procedure reset_file(file_number:char);
  137. begin
  138. @{$I-@}
  139. reset(ix_file,
  140. ccat('TEXT1$$.IX',file_number));
  141. @{$I+@}
  142. if ioresult <> 0 then
  143. begin
  144. writeln(messages,^G,
  145. ' -- Cannot find file ',ccat('TEXT1$$.IX',file_number));
  146. halt;
  147. end;
  148. end;
  149.  
  150. function getindex(x:string_pass;y:string_pass):integer;
  151. begin
  152.    getindex := pos(y,x);
  153.    end;
  154.  
  155. function trim(object:string_pass):string_pass;
  156. var i:integer;
  157. new_string:string_pass;
  158. begin
  159. i:=length(object)+1;
  160. repeat
  161.   decr(i);
  162.   until (object[i] <> ' ') or (i=1);
  163. if (object[i] = ' ') and (i=1)
  164. then new_string:=''
  165. else new_string:=copy(object,1,i);
  166. trim:=new_string;
  167. end;
  168. @z
  169.  
  170. @x   line 292
  171. @p procedure file_rewrite(file_number:char);
  172. begin
  173. if file_number = '9'
  174. then
  175. rewrite(sort_file,'NAME=TEXT1$$.INSORT.A,LRECL=1857,RECFM=V')
  176. else
  177. rewrite(ix_file,
  178. ccat(ccat('NAME=TEXT1$$.IX',str(file_number)),
  179. '.A,LRECL=2048,RECFM=V'));
  180. end;
  181. @y
  182. @p procedure file_rewrite(file_number:char);
  183. begin
  184. rewrite(ix_file,
  185. ccat('TEXT1$$.IX',file_number));
  186. end;
  187. @z
  188.  
  189. @x   line 343
  190. @ @<Global Types@>=
  191. @!string_pass=string_type(max_lrecl);
  192. @y
  193. @ @<Global Types@>=
  194. @!CursorList    = array[iBeamCursor..watchCursor] of CursHandle;
  195. @!string_pass=string_type(max_lrecl);
  196. @z
  197.  
  198. @x   line 444
  199. @ The {\it get\_numeric}
  200. function will take a packed array of length max\_pn\_alpha and convert
  201. that array (which is really the page number) into an integer.
  202.  
  203. @p function get_numeric(x_string:string_type(max_pn_alpha)):integer;
  204. var @!i:integer;
  205. begin
  206. readstr(x_string,i);
  207. get_numeric:=i;
  208. end;
  209. @y
  210. @ This function is needed to put the string to be converted by
  211. get\_numeric into the upper right portion of the string to be
  212. converted.
  213.  
  214. @p function shift_right(in_string:string_pass):decstr;
  215. var i,j:integer; temp:pn_alpha_type;
  216. begin
  217.   j:=0;
  218.   repeat incr(j); {find the first blank}
  219.    until (in_string[j] = ' ') or (in_string[j] = '') or
  220.          (j >= length(in_string));
  221.   for i:= 1 to sizeof(temp)-1 do temp[i]:=' ';
  222.   for i:=1 to j do temp[sizeof(temp)-j+i]:=in_string[i];
  223.   shift_right:=temp;
  224.   end;
  225.  
  226. @ The {\it get\_numeric}
  227. function will take a packed array of length max\_pn\_alpha and convert
  228. that array (which is really the page number) into an integer.
  229.  
  230. @p function get_numeric(x_string:string_pass):integer;
  231. var @!i:integer;
  232. begin
  233. get_numeric:=num2integer(str2num(shift_right(x_string)));
  234. end;
  235. @z
  236.  
  237. @x   line 459
  238. @p procedure strvalue(x:integer; var results:pass_pn_alpha);
  239. var
  240. temp:string_type(max_pn_alpha);
  241. begin
  242. writestr(temp,x);
  243. results:=ltrim(temp);
  244. end;
  245. @y
  246. @p procedure strvalue(X:integer; var results:pass_pn_alpha);
  247. var temp:decstr;
  248.     y:extended;
  249.     f:decform;
  250.     i,qq:integer;
  251. begin
  252.   f.style := fixeddecimal;
  253.   f.digits:=0;
  254.   y:=num2extended(x);
  255.   for i := 1 to decstrlen do temp[i] := ' ';
  256.   num2str(f,y,temp);
  257.   i:=1;
  258.   results:=temp;
  259.   end;
  260. @z
  261.  
  262. @x   line 470
  263. @p function strconv(x:pn_alpha_type):string_type(max_pn_alpha);
  264. var i:integer;
  265. temp:string_type(max_pn_alpha);
  266. begin
  267. temp:='';i := 1;
  268. with sort_record do begin
  269. repeat
  270. if x[i] <> ' ' then
  271. temp := ccat(temp,str(x[i]));
  272. incr(i);
  273. until (i > max_pn_alpha) or (x[i] = ' ');
  274. end;
  275. strconv:=temp;
  276. end;
  277. @y
  278. @p function strconv(x:pn_alpha_type):pass_pn_alpha;
  279. var i:integer;
  280. temp:string_type(max_pn_alpha);
  281. begin
  282. temp:='';i := 1;
  283. with sort_record do begin
  284. repeat
  285. if x[i] <> ' ' then
  286. temp := ccat(temp,x[i]);
  287. incr(i);
  288. until (i > max_pn_alpha) or (x[i] = ' ');
  289. end;
  290. strconv:=temp;
  291. end;
  292. @z
  293.  
  294. @x   line 626
  295. @ The {\it plsort} procedure is written in PL/1 to call the CMS sort program
  296. Syncsort. This was necessary since you cannot call Syncsort from PASCAL/VS.
  297. The fields to be sorted are defined internally in the {\it plsort}
  298. program. This should be the same as the three sort fields in {\it sort\_type}.
  299. @:sort_type@>
  300. @:plsort@> @^PL/1@>
  301. @^Syncsort@>
  302.  
  303. @p procedure plsort(var sort_rc:integer); fortran;
  304. @y
  305. @ The {\it LessRec} function is used by Turbo Pascal Database Toolbox's
  306. Sort routine. It returns true if record ``x'' is less than record ``y''.
  307. The record {\it sort\_type} is used for comparison.
  308. @:sort_type@>
  309.  
  310. @p function  LessRec(var x,y :sort_type):boolean;
  311. var Lower :boolean;
  312. begin Lower := (x.sort_part[1].field_level < y.sort_part[1].field_level);
  313. if not Lower then begin {x $\ge$ y}
  314. Lower := (x.sort_part[1].field_level =  y.sort_part[1].field_level);
  315. if Lower then begin {x = y}
  316. Lower := (x.sort_part[2].field_level < y.sort_part[2].field_level);
  317. if not Lower then begin {x $\ge$ y}
  318. Lower := (x.sort_part[2].field_level =  y.sort_part[2].field_level);
  319. if Lower then begin {x = y}
  320. Lower := (x.sort_part[3].field_level < y.sort_part[3].field_level);
  321. if not Lower then begin {x $\ge$ y}
  322. Lower := (x.sort_part[3].field_level =  y.sort_part[3].field_level);
  323. if Lower then begin {x = y}
  324. Lower := (x.abs_page_number < y.abs_page_number);
  325. if not Lower then begin {x $\ge$ y}
  326. Lower := (x.abs_page_number =  y.abs_page_number);
  327. if Lower then begin {x = y}
  328. Lower := (x.page_number < y.page_number);
  329. if not Lower then begin {x $\ge$ y}
  330. Lower := (x.page_number = y.page_number);
  331. if Lower then {x = y}
  332. Lower := (x.record_type < y.record_type);
  333. end; end; end; end; end; end; end; end; end;
  334. LessRec := Lower;
  335. end;
  336. @z
  337.  
  338. @x   line 643
  339. @ This function converts to all uppercase.
  340. Notice that this is an EBCIDIC conversion, not an ASCII conversion
  341. to uppercase.
  342.  
  343. @p function upper_case(x:char):char;
  344. var temp:char;
  345. begin
  346.   if (ord(x)>=129)and(ord(x)<=169) then
  347.       temp:=chr(ord(x)+64)
  348.   else temp:=x;
  349. upper_case:=temp;
  350. end;
  351. @y
  352. @ This function converts to all uppercase.
  353. Notice that this is an ASCII   conversion, not an EBCDIC  conversion
  354. to uppercase.
  355.  
  356. @p function upper_case(x:char):char;
  357. var temp:char;
  358. begin
  359.   if ord(x) >= "a" then
  360.       temp:=chr(ord(x)-@'40)
  361.   else temp:=x;
  362. upper_case:=temp;
  363. end;
  364. @z
  365.  
  366. @x   line 719
  367. @<Get Default Index Values@>
  368. @y
  369. writeln(messages);
  370. writeln(messages,'Reading in the input now...');
  371. total_recs := 0;
  372. @<Get Default Index Values@>
  373. @z
  374.  
  375. @x   line 722
  376. @<Read Next Record@>@/
  377. @y
  378. @<Read Next Record@>@/
  379. incr(total_recs);write(total_recs:6);gotoxy(1,6);
  380. @z
  381.  
  382. @x   line 728
  383. end;end;
  384. @y
  385. end;
  386. close(ix_file);
  387. writeln(messages);
  388. writeln(messages,'done reading the records. Starting to sort......');
  389. clock_time := tickcount;
  390. end;
  391. @z
  392.  
  393. @x   line 738
  394. if dosubstr(in_record,doindex(in_record,'=')+1) = 'no'
  395. @y
  396. if dosubstr(in_record,doindex(in_record,'=')+1,length(in_record))
  397.   = 'no'
  398. @z
  399.  
  400. @x   line 744
  401. if dosubstr(in_record,doindex(in_record,'=')+1) = 'no'
  402. @y
  403. if dosubstr(in_record,doindex(in_record,'=')+1,length(in_record))
  404.   = 'no'
  405. @z
  406.  
  407. @x   line 867
  408. @ Ok, the record has been processed, so write it to the output file.
  409.  
  410. @<Write Sort Record@>=
  411. sort_file@@:=sort_record;
  412. put(sort_file);
  413. @y
  414. @ Ok, the record has been processed, so write it to the output file
  415. using the procedure defined to Turbo Pascal's Database Toolbox.
  416.  
  417. @<Write Sort Record@>=
  418. SortRelease(sort_record);
  419. @z
  420.  
  421. @x   line 890
  422. The page number for a blind entry will always be 999999999.
  423.  
  424. @<Do Blind Entry@>=
  425. begin remove_characters(6);{Throw away the `\$\{\$\}be'}@/
  426. i := doindex(in_record,'{$}');
  427. curr_level:=2;
  428. write_print_chars(i-1);
  429. curr_level:=0;
  430. remove_characters(3);{Throw away the `\{\$\}'}
  431. sort_record.page_number := 999999999;
  432. @y
  433. The page number for a blind entry will always be 9999.
  434.  
  435. @<Do Blind Entry@>=
  436. begin remove_characters(6);{Throw away the `\$\{\$\}be'}@/
  437. i := doindex(in_record,'{$}');
  438. curr_level:=2;
  439. write_print_chars(i-1);
  440. curr_level:=0;
  441. remove_characters(3);{Throw away the `\{\$\}'}
  442. sort_record.page_number := 9999;
  443. @z
  444.  
  445. @x   line 976
  446. str_blind_entry := ccat(str_blind_entry,str(field_level[i]));
  447. @y
  448. str_blind_entry := ccat(str_blind_entry,field_level[i]);
  449. @z
  450.  
  451. @x   line 996
  452. @ If the {\it page\_string[1]} is less than zero, its alphabetic and
  453. roman numeral processing is necessary.
  454.  
  455. @<Do Sorted Non Blind Entry@>=
  456. with sort_record do begin
  457. if ord(page_string[1]) < ord('0')
  458. @y
  459. @ If the {\it page\_string[1]} is greater
  460.  than nine, its alphabetic and
  461. roman numeral processing is necessary.
  462.  
  463. @<Do Sorted Non Blind Entry@>=
  464. with sort_record do begin
  465. if ord(page_string[1]) > ord('9')
  466. @z
  467.  
  468. @x   line 1103
  469. then curr_str_page:=dosubstr(curr_str_page,2)
  470. @y
  471. then curr_str_page:=dosubstr(curr_str_page,2,length(curr_str_page))
  472. @z
  473.  
  474. @x   line 1182
  475. str_build := dosubstr(str_build,i+1);
  476. end;
  477. @<Get the Current Print Type of this Page Number@>;@/
  478. if ord(curr_str_page[1]) < ord('0') {Then its alphabetic}
  479. @y
  480. str_build := dosubstr(str_build,i+1,length(str_build));
  481. end;
  482. @<Get the Current Print Type of this Page Number@>;@/
  483. if ord(curr_str_page[1]) > ord('9') {Then its alphabetic}
  484. @z
  485.  
  486. @x   line 1195
  487. str_build := dosubstr(str_build,i+1);
  488. @y
  489. str_build := dosubstr(str_build,i+1,length(str_build));
  490. @z
  491.  
  492. @x   line 1311
  493. while not eof(sort_file) do begin
  494. sort_record:=sort_file@@;
  495. get(sort_file);
  496. @y
  497. file_rewrite(ix);
  498. clock_time := tickcount - clock_time;write(^G);
  499. writeln(messages,'It took ',clock_time/60.0:1:4,' seconds to sort ',
  500. total_recs:6,' records.');
  501. writeln(messages,'Now building the file to be formated with TEXT1...');
  502. while not SortEOS        do begin
  503. SortReturn(sort_record);
  504. @z
  505.  
  506. @x   line 1524
  507. @* Main Program.
  508. Ok, here is the main program. First we initialize (all\_blanks); then
  509. set the ix\_file for input and the sort\_file for output; read all of the
  510. entries, processing each one; close the files; sort; read the sorted file
  511. in and build the entries, writing them back to the ix\_file to be read in
  512. by the index markup. WHEW!!
  513.  
  514. @p
  515. begin @<Initialize Main@>@/
  516. termout(messages);
  517. reset_file(ix);@/
  518. file_rewrite(s_file_number); {Should always be file 9}@/
  519. read_all_entries;@/
  520. close(ix_file);@/
  521. close(sort_file);@/
  522. @<Sort the Index@>@/
  523. reset_file(s_file_number);@/
  524. file_rewrite(ix);@/
  525. build_sorted_index;@/
  526. end;
  527. @y
  528. @* Main Program.
  529. Ok, here is the main program. First we initialize (all\_blanks); then
  530. prompt to determine which index to use (1, 2, or 3).
  531. Next call Turbo Pascal's sort routine. And thats it.
  532.  WHEW!!
  533.  
  534. @p
  535. begin @<Initialize Main@>@/
  536. write('Which index are you processing (1, 2, or 3)? ');@/
  537. readln(ix);@/
  538. if (ix <> '1') and (ix <> '2') and (ix <> '3') then begin
  539. writeln(messages,
  540. 'You can only process indexes 1, 2, or 3. Start again.');
  541. halt; end;
  542. clearscreen;writeln('');
  543. writeln(messages,'Loading the sort routine....');
  544. writeln(messages);
  545. reset_file(ix);@/
  546. for m := iBeamCursor to watchCursor do begin
  547. curslist[m] := getcursor(m);
  548. hlock(handle(curslist[m]));end;setcursor(curslist[watchCursor]^^);
  549. showcursor;
  550. @<Sort the Index@>@/
  551. hidecursor;
  552. close(ix_file); {ix_file now has the index to be run through \TeX}
  553. write(messages,'Press any key to continue ');readln;
  554. end.
  555. @z
  556.  
  557.  
  558. @x   line 1548
  559. @ As mentioned earlier, {\it plsort} is an external PL/1 subroutine
  560. @^PL/1@>
  561. @^Syncsort@>
  562. which is used to call Syncsort to sort the file.
  563. The sort fields are as follows:
  564. @y
  565. @ As mentioned earlier, {\it TurboSort} is a Turbo Toolbox Database
  566.  subroutine
  567. which is used to sort the index file.
  568. The sort fields are as follows:
  569. @z
  570.  
  571. @x   line 1562
  572. sort_rc:integer;
  573. @y
  574. sort_rc:integer;
  575. @!ix:char;
  576. @z
  577.  
  578. @x   line 1564
  579. @ @<Sort the Index@>=
  580. plsort(sort_rc);
  581. if sort_rc = 0
  582.    then writeln(messages,'Index Successfully Completed')
  583.    else writeln(messages,'Index Failed');
  584. @y
  585. @ @<Sort the Index@>=
  586. sort_rc := TurboSort(sizeof(sort_type),@@read_all_entries,
  587. @@LessRec, @@build_sorted_index);
  588. if sort_rc = 0
  589.    then writeln(messages,'Index Successfully Completed')
  590.    else writeln(messages,'Index Failed');
  591. @z
  592.